%% 射频链路频响校正
clear; close all; clc;

filename = 'channelFlatness.csv'; % 信道数据
channeldata1 = readtable(filename).Var2-30;
channeldata=10.^(channeldata1./10); % 对数响应转换为线性响应

load('IQ.mat');
SR=640e6;

%%信道添加信道
H=channeldata(1:3:128*3);
ResponseStep=3e6;
channel_t = ifft(ifftshift(H));
channel_t = circshift(channel_t, floor(length(channel_t)/2));
g_temp_resampled = resample(channel_t, SR, length(channel_t)*ResponseStep);
be320MSR2_dis = conv(be320MSR2, g_temp_resampled, 'same');  % 保持相同长度

%%信道补偿
C_desiredH = 1 ./ H;
C_desiredH(abs(H) < 1e-6) = 1;  % 避免除零
C_desired_t = ifft(ifftshift(C_desiredH));
C_desired_t = circshift(C_desired_t, floor(length(C_desired_t)/2));
C_temp_resampled = resample(C_desired_t, SR, length(H)*ResponseStep);
be320MSR2_cal = conv(be320MSR2_dis, C_temp_resampled, 'same');  % 保持相同长度
